package io.renren.modules.course.controller;

import io.renren.common.utils.R;
import io.renren.modules.course.entity.ExamCourse;
import io.renren.modules.course.service.ExamCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Yang
 * @Date 2019/9/4 14:54
 */
@RestController
@RequestMapping("/exam")
public class ExamCourseController {

    @Autowired
    private ExamCourseService examCourseService;

    /***
     * 添加科目
     * @author Yang
     * @date 2019/9/4 14:59
     * @param examCourse :
     * @return : io.renren.util.ServerResponse
     */
    @GetMapping("/add")
    public R add(ExamCourse examCourse){
        examCourseService.save(examCourse);
        return R.ok();
    }

    /***
     * 删除科目
     * @author Yang
     * @date 2019/9/4 15:04
     * @param id :
     * @return : io.renren.util.ServerResponse
     */
    @GetMapping("/delete")
    public R delete(@RequestBody Long[] id){
        examCourseService.removeById(id);
        return R.ok();
    }

    /***
     * 更新科目
     * @author Yang
     * @date 2019/9/4 15:08
     * @param examCourse :
     * @return : io.renren.util.ServerResponse
     */
    @GetMapping("/update")
    public R update(ExamCourse examCourse){
        examCourseService.updateById(examCourse);
        return R.ok();
    }

    /***
     * 查询全部
     * @author Yang
     * @date 2019/9/4 15:15
     * @return : io.renren.util.ServerResponse
     */
    @GetMapping("/findAll")
    public R findAll(){
        final List<Map<String, Object>> list = examCourseService.listMaps();
        return R.ok().put("list",list);
    }
}
